package com.etc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.etc.dao.ArticleMapper;
import com.etc.dao.ArticledetailMapper;
import com.etc.entity.Article;
import com.etc.service.ArticleService;

@Service
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleMapper articleMapper;
	@Autowired
	private ArticledetailMapper articledetailMapper;
	
	@Override
	public List<Article> findAllArticleInfo() {
		List<Article> articleInfoList = articleMapper.findAllArticleInfo();
		return articleInfoList;
	}

	@Override
	public int insertArticle(Article article) {
		return articleMapper.insertArticle(article);
	}

	@Override
	public List<Article> selectArticleOrderByAscore() {
		
		return articleMapper.selectArticleOrderByAscore();
	}

	@Override
	public List<Article> selectArticleOrderByPageview() {
		return articleMapper.selectArticleOrderByPageview();
	}

	@Override
	public Article selectArticleByAid(Integer aid) {
		
		return articleMapper.selectByPrimaryKey(aid);
	}

	@Override
	public int updateArticle(Article article) {
		
		return articleMapper.updateByPrimaryKeySelective(article);
	}

	@Override
	public Article selectNextArticle(Integer aid) {
		return articleMapper.selectNextArticle(aid);
	}

	@Override
	public List<Article> findAStatusIsNoArticleInfo() {
		return articleMapper.findArticleInfoByAStatus(0);
	}

	@Override
	public List<Article> findAStatusIsYesArticleInfo() {
		return articleMapper.findArticleInfoByAStatus(1);
	}

	@Override
	public List<Article> findArticleInfoByLikeATitle(String atitle) {
		return articleMapper.findArticleInfoByLikeATitle(atitle);
	}

	@Override
	public Boolean deleteArticleByAid(Integer aid) {
		int i = articleMapper.deleteByPrimaryKey(aid);
		int j = articledetailMapper.deleteByPrimaryKey(aid);
		if (i>0&&j>0) {
			return true;
		}
		return false;
	}

}
